<!-- components/Account.vue -->
<template>
	<view class="account-warpper">
		<!-- 标题 -->
		<Navbar title=""></Navbar>
		<view class="card flex-between">
			<view class="card-left">
				<view class="card-title">
					<text>{{cardTitle}}</text>
				</view>
				<view class="card-price ">
					<view class="">
						<text>¥</text>
						<text class="price">{{price}}</text>
					</view>
				</view>
			</view>
			<view class="card-right">
				<button @click="toTransferIn" v-if="title=='生息账户'" class="right-btn">转入积分</button>
				<button @click="toWithdrawal" v-if="title=='现金账户'" class="right-btn"
					style="margin-bottom: 20rpx;">提现</button>
				<button @click="toTransfer(title)" v-if="title=='现金账户' || title=='积分账户'" class="right-btn">转赠</button>
			</view>
		</view>
		<view class="account">

			<view class="account-content">
				<view class="tabs">
					<view class="tab" v-for="(tab,index) in tabs" :key="index" @click="activeTab(index)"
						:class="{'activeTab':index===activeIndex}">
						{{tab.title}}

					</view>
				</view>
				<view class="data-wapper" v-if="activeIndex===0">
					<view class="data income" v-if="incomeData.length">
						<view class="list" v-for="(item,index) in incomeData" :key="index">
							<view class="left">
								<view class="text">{{item.stage}}
									<image src="/static/index_slices/wenhao.png" @click="changeRemark(index,'incomeData')"></image>
									<view class="remark" v-if="item.isremark">{{item.remark}}</view>
								</view>
								<view>
									<text class="other" v-if="title=='生息账户'">订单号: </text>
									<text class="other">{{item.createtime}}</text>
								</view>
							</view>
							<view class="right">
								<text>{{item.change_value}}</text>
							</view>
						</view>
					</view>
					<template v-else>
						<NotData></NotData>
					</template>
				</view>
				<view class="data-wapper" v-if="activeIndex===1">
					<view class="data income" v-if="expensesData.length">
						<view class="list" v-for="(item,index) in expensesData" :key="index">
							<view class="left">
								<view class="text">{{item.stage}}
									<image src="/static/index_slices/wenhao.png" @click="changeRemark(index,'expensesData')"></image>
									<view class="remark" v-if="item.isremark">{{item.remark}}</view>
								</view>
								<view>
									<text class="other">{{item.createtime}}</text>
								</view>
							</view>
							<view class="right">
								<text>{{item.change_value}}</text>
							</view>
						</view>
					</view>
					<template v-else>
						<NotData></NotData>
					</template>
				</view>
			</view>

		</view>
	</view>
</template>

<script setup>
	import {
		defineEmits
	} from 'vue';
	import {
		ref,
		reactive,
		computed
	} from 'vue'
	import Navbar from './Navbar.vue'
	import NotData from './NotData.vue'
	import {
		number
	} from '../uni_modules/uview-plus/libs/function/test'
	import {
		onLoad
	} from '@dcloudio/uni-app'
	const emit = defineEmits(['typeChange', 'clearData']);
	const price = ref(0)
	onLoad((options) => {
		if (options) {
			price.value = options.price
			
		}
	})
	// 接收传参
	const props = defineProps({
		title: {
			type: String,
			default: '积分账户'
		},

		incomeData: {
			type: Array,
			default: []
		},
		expensesData: {
			type: Array,
			default: () => [

			]
		}

	})
	//remark显示
	const changeRemark = (i,name) => {
		props[name] = props[name].map((item, index) => {
			item.isremark = index == i ? true : false
			return item
		})
	}
	// 卡片信息
	const cardTitle = computed(() => {
		if (props.title == '积分账户') return ' 我的积分'
		if (props.title == '现金账户' || props.title == '复消账户') return ' 我的钱包'
		if (props.title == '生息账户') return '我的生息'
		if (props.title == '提现') return '可提现金额'
	})
	const incomeTitle = computed(() => {
		if (props.title == '积分账户') return ' 奖励'
		if (props.title == '现金账户' || props.title == '复消账户') return ' 充值'
		if (props.title == '生息账户') return '佣金'
	})

	// 切换列表
	const tabs = reactive([{
		title: '收入'
	}, {
		title: '支出'
	}])
	const activeIndex = ref(0)
	const activeTab = (index) => {
		activeIndex.value = index
		emit('clearData')
		setTimeout(function() {
			emit('typeChange', 1, index + 1);
		}, 200)

	}

	// 转赠积分
	const toTransfer = (title) => {
		uni.navigateTo({
			url: '/goodsPages/pages/goods/points-transfer?title=' + title
		})
	}
	// 转入积分
	const toTransferIn = () => {
		uni.navigateTo({
			url: '/goodsPages/pages/goods/points-transferin'
		})
	}
	// 提现
	const toWithdrawal = () => {
		uni.navigateTo({
			url: `/otherPages/pages/other/withdrawal?price=${price.value}`
		})
	}
</script>

<style lang="scss" scoped>
	.account-warpper {
		background-color: transparent;

		.card {
			width: 690rpx;
			height: 220rpx;
			background-image: url('/static/index_slices/account_bg.png');
			background-repeat: no-repeat;
			background-size: 690rpx 220rpx;
			margin: 30rpx 30rpx 0;
			position: fixed;
			z-index: 3;

			padding-left: 56rpx;
			color: #313029;
			font-weight: bold;
			font-size: 26rpx;

			.card-price {
				margin-top: 21rpx;
				font-size: 40rpx;
				font-weight: normal;
				display: flex;
				align-items: center;

				.price {
					font-weight: bold;
					font-size: 50rpx;
					margin-left: 10rpx;
					margin-right: 32rpx;

				}

				.details {

					display: inline-block;
					text-align: center;
					font-size: 24rpx;
					color: #313029;
					width: 85rpx;
					height: 48rpx;
					line-height: 48rpx;
					border-radius: 24rpx;
					border: 1px solid #74AC80;
				}

			}

			button.right-btn {
				padding: 0 34rpx;
				right: 92rpx;
				background: linear-gradient(to right, #FFB600, #FF6C00);
				color: #fff;
				height: 68rpx;
				font-size: 26rpx;
				border-radius: 34rpx;
				border: none !important;

				&::after {
					border: 1px solid rgba(0, 0, 0, 0);

				}
			}
		}

		.account-content {
			padding-top: 260rpx;

			.tabs {
				padding: 30rpx;
				display: flex;
				text-align: center;

				.tab {
					color: #222222;
					font-size: 28rpx;
					width: 345rpx;
					height: 68rpx;
					line-height: 68rpx;
					background-image: url('/static/index_slices/tab_bg1.png');
					background-repeat: no-repeat;
					background-size: 100%;
				}

				.activeTab {
					background-image: url('/static/index_slices/tab_bg2.png');
					color: #fff;
				}
			}

		}

		.data-wapper {
			padding: 30rpx;

			.data {



				.list {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 40rpx;
					padding: 0 10rpx 30rpx;
					border-bottom: 1px solid #E7E7E7;

					.left {
						color: #222222;
						font-size: 28rpx;
						flex: 1;

						text {
							display: block;
						}

						.text {
							display: inline-flex;
							align-items: center;
							position: relative;

							image {
								width: 30rpx;
								height: 30rpx;
								margin-left: 10rpx;
							}

							.remark {
								position: absolute;
								left: 100%;
								margin-left: 20rpx;
								min-width: 300rpx;
								padding: 10rpx;
								background-color: white;
								border-radius: 10rpx;
								top: 0;
								font-size: 20rpx;
							}

							.remark::before {
								display: inline-block;
								vertical-align: middle;
								content: '';
								border-right: solid 8px white;
								border-top: solid 4px transparent;
								border-bottom: solid 4px transparent;
								position: absolute;
								right: 100%;
								top: 10rpx;
							}
						}


						.other {
							margin-top: 22rpx;
							font-size: 22rpx;
							color: #999999;
						}
					}

					.right {
						color: #000E25;
						font-size: 36rpx;
						font-weight: bold;
					}
				}

			}
		}
	}
</style>